package downstream

import (
	"github.com/smartwalle/alipay/v3"
	"pay/internal/constant"
	"pay/internal/model"
	"pay/pkg/ecode"
	"pay/pkg/env"
)

func (d *Downstream) initAlipayClient(envType env.Type) (err error) {
	if d.AlipayClient, err = alipay.New(
		model.BootInfo.AlipayServiceProviderAppId,
		model.BootInfo.AlipayServiceProviderPrivateKey,
		true,
	); err != nil {
		err = ecode.AppendMessage(constant.ErrSystemError, "支付宝执行器初始化失败: %s", err.Error())
		return
	}
	if err = d.AlipayClient.LoadAliPayPublicKey(model.BootInfo.AlipayServiceProviderPublicKey); err != nil {
		err = ecode.AppendMessage(constant.ErrSystemError, "支付宝验签公钥初始化失败: %s", err.Error())
		return
	}
	return
}
